package ru.ruchin.tek.employees.web;

import java.util.Map;
import javax.servlet.ServletContext;
import ru.ruchin.tek.employees.data.EmployeeStorage;

/**
 *
 * @author yruchin
 */
public class RemoveObjectQueryHandler implements QueryHandler {
    @Override
    public String handleQuery(Map<String, String[]> query, ServletContext context) {
        EmployeeStorage storage = (EmployeeStorage)context.getAttribute(EmployeeStorage.CONTEXT_KEY);
        long id = Long.parseLong(query.get("id")[0]);

        if (query.get("department") != null) {
            storage.removeDepartment(id);
        } else {
            storage.removeEmployee(id);
        }

        return "";
    }
}
